<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>设备管理</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,address=no"/>
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../css/zy_common.css"/>
    <link rel="stylesheet" href="../css/zy_base.css"/>
</head>
<body>
    <div class="manage_tit flex font15 col9 bw pos_f_t">
        <span class="active">全部</span>
        <span>在线</span>
        <span>离线</span>
        <span>故障</span>
    </div>
    <div class="manageBox">
        <ul>
            <!--<li class="bw plr24 mt20">-->
                <!--<div class="ptb30 bdb col9 font14">-->
                    <!--<p class="font15 flex_sb mb20"><span class="col3">设备编号：654564654565</span><span class="color2">在线</span></p>-->
                    <!--<p class="mb10">地址：广东省东莞市南城区高盛科技大厦</p>-->
                    <!--<p class="mb10 flex_a"><span class="mr70">库存：100</span><span class="mr70">代理人：勇仔</span><span>运维人员：波哥</span></p>-->
                    <!--<p>2018-06-06  12:23:56</p>-->
                <!--</div>-->
                <!--<div class="flex jce">-->
                    <!--<em class="editBox h80 flex_a"><img src="../img/edit.png" alt=""><span class="ml10 col9 font14">编辑</span></em>-->
                    <!--<em class="delBox h80 flex_a ml40"><img src="../img/del.png" alt=""><span class="ml10 col9 font14">删除</span></em>-->
                <!--</div>-->
            <!--</li>-->
        </ul>
    </div>
    <footer class="h100 flex font15 pos_f_b">
        <span class="flex1 bgc1 colw flex_aj" id="bd_device">绑定设备</span>
        <span class="flex1 bgc4 color1 flex_aj" onclick="location.href='./zy_log.html'">开锁日志</span>
        <span class="flex1 bw col3 flex_aj pos_r"  onclick="location.href='./zy_error_mes.html'">异常信息 <i class="flex_aj colw bgc2 font13 mesBox"></i> </span>
    </footer>
</body>
</html>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/dlc.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
    var page = 0;
    // 每页展示10个
    var size = 10;
    var status='';
        $(function () {
            addEventback();//返回刷新
            getData();
            $('.manage_tit span').click(function () {
                var index = $(this).index();
                $(this).addClass('active').siblings().removeClass('active');
                if(index == 0){
                    status='';
                }else{
                    status=index;
                }
                page=0;
                getData();
            })

            //编辑
            $('.manageBox').on('click','.editBox',function () {
                var deviceNo = $(this).parents('li').data('macno');
                var imei = $(this).parents('li').data('imei');
                var price = $(this).parents('li').data('goods_price');
                location.href='./zy_bd_device.html?macno='+deviceNo+'&imei='+imei+'&price='+price+'&type=1';

            });

            //删除
            $('.manageBox').on('click','.delBox',function () {
                var that = this;
                dlctipbox.confirm('是否删除该设备？',function (flag) {
                    if(flag==1){
                        var deviceNo = $(that).parents('li').data('macno');
                        dlctipbox.loading('请稍后');
                        dlc_request('/api/device/deleteDevice',{deviceNo:deviceNo},function (res) {
                            dlctipbox.clear();
                            if(res.code==1){
                                dlctipbox.show('删除成功');
                                setTimeout(function () {
                                    location.reload();
                                },1500);
                            }else{
                                dlctipbox.show(res.msg);
                            }
                        })
                    }
                })
            });

        })

    //异常信息
    dlc_request('/api/exceptionMessage/getExceptionMessageList',{agentId:getLocalData('fd_id')},function (res) {
        dlctipbox.clear();
        if(res.code==1){
            $('.mesBox').text(res.data.length<100?res.data.length:'...');
        }else{
            console.log(res.msg);
        }
    })



    dlc_request('/wx/getTicket',{},function(res){
        console.log(res);
        if(res.errmsg=='ok'){
            var timestamp=(new Date().getTime()/1000).toFixed(0);
            var nonceStr=Math.random().toString(36).substr(2);
            var ticket=wx_js(res.ticket,timestamp,nonceStr);
            wx.config({
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端//alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                appId: 'wx2c49fec17dc24b80', // 必填，公众号的唯一标识
                timestamp:timestamp, // 必填，生成签名的时间戳
                nonceStr:nonceStr, // 必填，生成签名的随机串
                signature:ticket ,// 必填，签名，见附录1
                jsApiList: ['checkJsApi',
                    'onMenuShareTimeline',
                    'onMenuShareAppMessage',
                    'onMenuShareQQ',
                    'onMenuShareWeibo',
                    'hideMenuItems',
                    'showMenuItems',
                    'hideAllNonBaseMenuItem',
                    'showAllNonBaseMenuItem',
                    'translateVoice',
                    'startRecord',
                    'stopRecord',
                    'onRecordEnd',
                    'playVoice',
                    'pauseVoice',
                    'stopVoice',
                    'uploadVoice',
                    'downloadVoice',
                    'chooseImage',
                    'previewImage',
                    'uploadImage',
                    'downloadImage',
                    'getNetworkType',
                    'openLocation',
                    'getLocation',
                    'hideOptionMenu',
                    'showOptionMenu',
                    'closeWindow',
                    'scanQRCode',
                    'chooseWXPay',
                    'openProductSpecificView',
                    'addCard',
                    'chooseCard',
                    'openCard'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
            });
            wx.ready(function(){
                $('#bd_device').click(function () {
                    wx.scanQRCode({
                        needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
                        scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
                        success: function (res) {
                            var macno=getUrlParam('deviceNo','',res.resultStr);
                            var imei=getUrlParam('imei','',res.resultStr);
                            dlctipbox.loading('请稍后');
                            dlc_request('/api/device/getDeviceDetail',{deviceNo:macno},function (res) {
                                dlctipbox.clear();
                                console.log(res);
                                if(res.code==1){
                                    if(res.data.status==2){
                                        dlctipbox.alert('设备离线');
                                    }
                                    if(res.data.status==3){
                                        dlctipbox.alert('设备故障')
                                    }
                                    if(res.data.status==1){
                                        location.href ='./zy_bd_device.html?macno='+macno+'&imei='+imei+'&price='+res.data.goodsPrice; // 当needResult 为 1 时，扫码返回的结果
                                    }
                                }else{
                                    dlctipbox.show(res.msg);
                                }
                            })

                        },
                        error:function(err){
                            alert(JSON.stringify(err));
                        }
                    });
                });
            })
        }else{
            //hideLoading();
            console.log(res.msg);
        }
    })


    function getData(){
        var data={
            id:getLocalData('fd_id'),
            type:'2'
        };
        if(status){
            data.status=status
        }
        dlctipbox.loading('请稍后');
        dlc_request('/api/device/getDeviceList',data,function (res) {
            console.log(res);
            dlctipbox.clear();
            if(res.code==1){
                var str = '';
                res.data.forEach(function (item,index) {
                    str+='<li class="bw plr24 mt20" data-macno="'+item.deviceNo+'" data-imei="'+item.imei+'" data-goods_price="'+item.goodsPrice+'">'+
                        '<div class="ptb30 bdb col9 font14">'+
                        '<p class="font15 flex_sb mb20"><span class="col3">设备编号：'+item.deviceNo+'</span><span class="color2">'+(item.status==1?'在线':item.status==2?'离线':'故障')+'</span></p>'+
                        '<p class="mb10">地址：'+item.addressDetail+'</p>'+
                        '<p class="mb10 flex_a"><span class="mr70">库存：'+item.inventory+'</span><span class="mr70">代理人：'+item.agentName+'</span><span>运维人员：'+item.opsName+'</span></p>'+
                        '<p>'+format(item.createTime,'Y-m-d H:i:s')+'</p>'+
                        '</div>'+
                        '<div class="flex jce">'+
                        '<em class="editBox h80 flex_a"><img src="../img/edit.png" alt=""><span class="ml10 col9 font14">编辑</span></em>'+
                        '<em class="delBox h80 flex_a ml40"><img src="../img/del.png" alt=""><span class="ml10 col9 font14">删除</span></em>'+
                        '</div>'+
                        '</li>';
                });
                if(str){
                    $('.manageBox ul').html(str);
                }else{
                    $('.manageBox ul').html(emptyTip('暂无数据'));
                }

            }
        });
    }
</script>